<?php 
require './Core/Common.php';
use xfyzf\api\controller\Examine;
use xfyzf\api\controller\AlipayService_dmf;
$queryArr  = input();
$pid=intval($queryArr['pid']);
if(empty($pid))exitjson(-1,'pid不存在');
$sql = "SELECT * FROM pay_user WHERE pid=:pid LIMIT 1";
$params = ['pid' => $pid];
$userrow = safeSqlQuery($sql, $params)['result'][0]??'';
if(!$userrow)exitjson(-1,'pid不存在');
if($userrow['zt']!=1)exitjson('此账号已被封禁，已被禁止发起支付，如您是本支付平台商户，请联系站长');

Examine::examine($queryArr,$userrow,true);

$type         = $queryArr['type'];
$QR_row = Examine::QR_row($type,$userrow,$queryArr['money'],true);
$time = time();
$price    = Examine::amount($type,$queryArr);
$trade_no = date("YmdHis").rand(11111,99999);
$ip = http_ip();
Examine::wxpayqr_url();
if(!Examine::order())exitjson(-1,'写入订单失败 请检查数据 是否合法且完整');

$Xf_MOSHI         = $userrow['INPUTFREE']??'';
if($QR_row['cookie'] == 'xfqydmfxy' && $type == 'alipay'){
    $f2fid          = $QR_row['alipayAppId'];
    $f2fpubli        = $QR_row['appPrivateKey'];//私钥
    $sign           = MD5($trade_no);
    $notifyUrl		= $httphost.'/Submit/F2f_notify';
    $signType = 'RSA2';
    $aliPay = new AlipayService_dmf();
    $aliPay->setAppid($f2fid);
    $aliPay->setReturnUrl($httphost);
    $aliPay->setNotifyUrl($notifyUrl);
    $aliPay->setRsaPrivateKey($f2fpubli);
    $aliPay->setTotalFee($price);
    $aliPay->setOutTradeNo($trade_no);
    $aliPay->setOrderName($srow['name']);
    $result = $aliPay->doPay();
    $result = $result['alipay_trade_precreate_response'];
    if($result['code'] && $result['code']=='10000'){
       $qrcode = $result['qr_code'];
       $code_url = '';
    }
}else{
    $qrdata = Examine::mapiqrcode($QR_row,$trade_no,$userrow,$price);
    $qrcode = $qrdata['qrcode'];
    $code_url = $qrdata['code_url'];
}
$data = array(
    "money" => $price,
    "type" => $type,
    "qrcode" => $qrcode,
    "code_url" => $code_url,
    "trade_no"=>$trade_no,
    "out_trade_no"=>$queryArr['out_trade_no']
    );
Examine::exitWithMessage(1,"发起成功,请支付".$price."元,不要多付也不要少付",$data);
?>